a11y: Skip atspi.Cache signals for hidden elements
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 19 Nov 2020 14:46:01 +0000 (14:46 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 19 Nov 2020 15:20:56 +0000 (15:20 +0000)
If the accessible object is hidden, we can skip the emission of the
AddAccessible and RemoveAccessible signals on the cache, as those
objects won't be visible in the accessibility tree.

gtk/a11y/gtkatspicache.c

index 81bfd030f262d1f3a553ddb970f16021b8a4b79a..10736341e51cb8a9553990037d57377d86bc0398 100644 (file)
@@ -176,6 +176,18 @@ static void
 emit_add_accessible (GtkAtSpiCache   *self,
                      GtkAtSpiContext *context)
 {
+  GtkATContext *at_context = GTK_AT_CONTEXT (context);
+
+  /* If the context is hidden, we don't need to update the cache */
+  if (gtk_at_context_has_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN))
+    {
+      GtkAccessibleValue *is_hidden =
+        gtk_at_context_get_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN);
+
+      if (gtk_boolean_accessible_value_get (is_hidden))
+        return;
+    }
+
   GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("(" ITEM_SIGNATURE ")"));
 
   collect_object (self, &builder, context);
@@ -194,6 +206,18 @@ static void
 emit_remove_accessible (GtkAtSpiCache   *self,
                         GtkAtSpiContext *context)
 {
+  GtkATContext *at_context = GTK_AT_CONTEXT (context);
+
+  /* If the context is hidden, we don't need to update the cache */
+  if (gtk_at_context_has_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN))
+    {
+      GtkAccessibleValue *is_hidden =
+        gtk_at_context_get_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN);
+
+      if (gtk_boolean_accessible_value_get (is_hidden))
+        return;
+    }
+
   GVariant *ref = gtk_at_spi_context_to_ref (context);
 
   g_dbus_connection_emit_signal (self->connection,